-- print('lesson11 start....')





-- print(package.path)
-- --package.path = [[D:\BawayWork20221012\LuaEditor6.30\lua]]
-- print(package.path)
-- print("nnnnnn"..b)

-- local a = require "Lesson08"

-- print("nnnnnn"..a)

--package.path = package.path ..';..\\?.lua';
--print(package.path)

--local b = require "lesson08"

--print("nnnnnnnnn"..a.a)

--print(package.path)

--print(package.cpath)

--local m = require "Lesson11_model"

--[[
local m = require "Lesson11_model2"

local c1 = m.new(0, 1)
local c2 = m.new(1, 2)

local ret = m.sub(c1, c2)
print(ret.r, ret.i)
--]]


--local other = { foo = 3, kk= 55, {888,999}, 5555 }
--local  t = setmetatable({foo = 4}, { __index = other })
--local t2 = getmetatable(t)

--print(t.kk)

--[[
for k,v in pairs(t2) do
	print(k ,v)
	print(v[1][1])
end
--]]

--[[
mytable = setmetatable({key1="keyvalue1"},
{
    __index= function(t,key)

	--print(t.key1)

      if key=="key2" then
        return "metatableValue222"
      else
		--print(".....")
        return nil
		end
    end
  })

mytable2 = setmetatable({}, {__index = mytable})

print(mytable2.key2)
--]]

-- ��ֻ����ʽ���ļ�
--file = io.open("1.txt", "w")

-- ����Ĭ�������ļ�Ϊ test.lua
--io.input(file)

-- ����ļ���һ��
--print(io.read())

-- �رմ򿪵��ļ�
--io.close(file)
-- ����Ĭ������ļ�Ϊ test.lua
--io.output(file)

-- ���ļ����һ������ Lua ע��
--io.write("���д")

-- �رմ򿪵��ļ�
--io.close(file)




-- �Ը��ӵķ�ʽ��ֻд�ļ�
--file = io.open("1.txt", "a")

-- ���ļ����һ������ Lua ע��
--file:write("�й���")

-- �رմ򿪵��ļ�
--file:close()

-- ��ֻ����ʽ���ļ�
--file = io.open("1.txt", "r")

-- ����ļ���һ��
--print(file:read())

-- �رմ򿪵��ļ�
--file:close()

local shape = {
	h = 0, --�߶�
	w = 0, --����
	p = 1000, --�ܳ�
	a = 0, --���


	

	calc_p = function(self) --�����ܳ�
		print("called shape p"..self.p)
		return self.p
	end,

	calc_a = function(self) --�������
		print("called shape a")
		return 0
	end
}

local triangle = {

	new = function (self, w, h)
		local t = {}
		setmetatable(t, {__index = self})
		t.w = w
		t.h = h
		return t
	end,

	calc_p = function(self)
		print("called triangle p")
		return self.w * self.h
	end,

	calc_a = function(self)
	print("called triangle a")
		return self.h * self.w * 0.5
	end
}
setmetatable(triangle, {__index = shape})


local tt1 = triangle:new(10,20)
local tt2 = triangle:new(200,300)

print(tt1.p)


-- print(tt1.calc_p())
-- print(tt1.calc_a())

-- print(tt1.w, tt2.h, tt2:calc_a(), tt1:calc_p())



